package com.daxue.lcm.api.grpc.utis;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @author daxue0929
 * @date 2022/10/9
 */

public class Utils {


    private static final ObjectMapper MAPPER = new ObjectMapper();


    public static <T> T asValue(
        String value, Class<T> valueType
    ) throws Exception {
        try {
            return MAPPER.readValue(value, valueType);
        } catch (IOException e) {
            throw new Exception(e);
        }
    }


    public static <T> T asValue(
        String value, TypeReference<T> valueTypeRef
    ) throws Exception {
        try {
            return MAPPER.readValue(value, valueTypeRef);
        } catch (IOException e) {
            throw new Exception(e);
        }
    }


}
